package com.vay.de.dang.online.util;

import android.os.Build;

import com.vay.de.dang.online.ui.BaseActivity;
import com.permissionx.guolindev.PermissionX;
import com.permissionx.guolindev.callback.RequestCallback;

public class PermissionUtil {

    public static String[] getLoginPermission() {
        return new String[]{"android.permission.ACCESS_COARSE_LOCATION",
                "android.permission.READ_PHONE_STATE",
                "android.permission.ACCESS_NETWORK_STATE",
                "android.permission.ACCESS_WIFI_STATE"};
    }

    public static String[] getApplyPermission() {
        // android 13
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
            return new String[]{"android.permission.ACCESS_COARSE_LOCATION",
                    "android.permission.READ_PHONE_STATE",
                    "android.permission.ACCESS_NETWORK_STATE",
                    "android.permission.ACCESS_WIFI_STATE",
                    "android.permission.BLUETOOTH",
                    "android.permission.BLUETOOTH_CONNECT"};
        }
        // 12
        else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
            return new String[]{"android.permission.ACCESS_COARSE_LOCATION",
                    "android.permission.READ_PHONE_STATE",
                    "android.permission.ACCESS_NETWORK_STATE",
                    "android.permission.ACCESS_WIFI_STATE",
                    "android.permission.BLUETOOTH",
                    "android.permission.BLUETOOTH_CONNECT"};
        } else {
            return new String[]{"android.permission.BLUETOOTH",
                    "android.permission.ACCESS_COARSE_LOCATION",
                    "android.permission.READ_PHONE_STATE",
                    "android.permission.ACCESS_NETWORK_STATE",
                    "android.permission.ACCESS_WIFI_STATE"};
        }
    }

    public static String[] getTakeImage() {
        return new String[]{"android.permission.CAMERA"};
    }

    public static void requestAll(BaseActivity activity, RequestCallback callback) {
        requestPermission(activity, getApplyPermission(), callback);
    }

    public static void requestPermission(BaseActivity activity,
                                         String[] permission,
                                         RequestCallback callback) {
        PermissionX.init(activity)
                .permissions(permission)
                .request(callback);
    }

    public static boolean checkPermission(BaseActivity activity, String[] permissions) {
        for (String permission : permissions) {
            if (!PermissionX.isGranted(activity, permission)) {
                return false;
            }
        }
        return true;
    }

}
